import random
class Sort:
    def __init__(self, arr_num, num_range):
        self.arr = []
        self.arr_num = arr_num # 列表存多少元素
        self.num_range = num_range # 随机数范围
        self.__creat_random_num()
    def __creat_random_num(self):
        for i in range(self.arr_num):
            self.arr.append(random.randint(0, self.num_range - 1))

    def bubble_sort(self):
        arr = self.arr
        for i in range(self.arr_num, 1 ,-1): # 外层控制无序数数目
            flag = True # 哨兵，如果已经有序，则跳出循环
            for j in range(i - 1):
                if arr[j] > arr[j + 1]:
                    arr[j], arr[j + 1] = arr[j + 1], arr[j]
                    flag = False
            if flag:
                break

if __name__ == '__main__':
    s = Sort(10, 100)
    print(s.arr)
    s.bubble_sort()
    print(s.arr)